package com.weirong.smartvault.backservice.entity_model;

import com.weirong.smartvault.dao.DictRepository;
import com.weirong.smartvault.dao.EquipmentRepository;
import com.weirong.smartvault.entity.Dict;
import com.weirong.smartvault.entity.Equipment;
import com.weirong.smartvault.entity.EquipmentErrorLog;
import com.weirong.smartvault.common.tools.spring.context.SpringContextUtil;
import com.weirong.smartvault.backservice.util.common.DateUtil;

/**
 * 于2017/11/30由 KFEB4 创建 .
 */
public class EquipmentErrorLogModel {
    private EquipmentErrorLog equipmentErrorLog;
    private DictRepository dictRepository;
    private EquipmentRepository equipmentRepository;
    public EquipmentErrorLogModel(EquipmentErrorLog equipmentErrorLog){
        this.equipmentErrorLog = equipmentErrorLog;
        this.dictRepository = SpringContextUtil.getBean(DictRepository.class);
        this.equipmentRepository = SpringContextUtil.getBean(EquipmentRepository.class);
    }
    public String getEquipmentType(){
        String code = equipmentErrorLog.getEquipmentType();
        Dict dict = dictRepository.findDictByCode(code);
        return dict.getName();
    }
    public String getEquipmentPart(){
        Equipment equipment = equipmentRepository.findByEquipmentTypeAndEquipmentPart(equipmentErrorLog.getEquipmentType(),equipmentErrorLog.getEquipmentPart());
        return equipment.getEquipmentPartName();
    }
    public String getErrorContent(){
        return equipmentErrorLog.getErrorContent();
    }
    public String getCreateTime(){
        return DateUtil.getNomalString(equipmentErrorLog.getCreateTime());
    }
}
